package com.tchhy.provider.repository.partner

import com.tchhy.provider.repository.BaseRepository
import com.tchhy.provider.api.partnerapi.WorkApi
import com.tchhy.provider.net.RetrofitFactory
import com.tchhy.provider.data.common.BaseResp
import com.tchhy.provider.data.common.EmptyResp
import com.tchhy.provider.data.partner.response.MedicineDetailResp
import com.tchhy.provider.data.partner.MedicineKitDetailRequestModel
import com.tchhy.provider.data.partner.MedicineKitSalesInfo
import com.tchhy.provider.data.partner.request.*
import com.tchhy.provider.data.partner.response.*
import io.reactivex.Observable

/**
 * @author: admin
 * @date: 2019/8/20
 * @des:
 *
 **/
class WorkRepository : BaseRepository() {


    /**
     * @description 提交用户信息
     * @param
     * @return
     * @author admin
     * @time 2019/8/20
     */
    fun submitPurchaserInfo(submitChaseInfo: SubmitChaseInfo): Observable<EmptyResp> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .submitPurchaseInfo(getRequestJsonBody(submitChaseInfo))
    }

    /**
     * @description 提交用户信息
     * @param
     * @return
     * @author admin
     * @time 2019/8/20
     */
    fun getPartnerArea(): Observable<BaseResp<PartnerAreaRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getPartnerArea()
    }

    /**
     * @description 获取药箱详情
     * @param
     * @return
     * @author admin
     * @time 2019/8/21
     */
    fun getMedicineKitDetail(id: String): Observable<BaseResp<ApplyMedicineRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .applyDrugDetail(id)
    }

    /**
     * @description 获取药箱详情
     * @param
     * @return
     * @author admin
     * @time 2019/8/21
     */
    fun getMedicineKitDetail(medicineKitDetailRequestModel: MedicineKitDetailRequestModel): Observable<BaseResp<MedicineDetailResp>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getMedicineKitDetail(mapOf("kitId" to medicineKitDetailRequestModel.kitId.toString()))
    }


    /**
     * @description 获取药箱销售详情
     * @param
     * @return
     * @author admin
     * @time 2019/8/21
     */
    fun getMedicineKitSalesDetail(): Observable<BaseResp<MedicineKitSalesInfo>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getMedicineKitSales()
    }

    /**
     * @description 获取付款码
     * @param
     * @return
     * @author admin
     * @time 2019/8/22
     */
    fun getPaymentCode(paymentCodeModel: PaymentCodeModel): Observable<BaseResp<PaymentCodeInfo>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getPaymentCode(getRequestJsonBody(paymentCodeModel))
    }

    /**
     * @description 获取服务订单详情
     * @param
     * @return
     * @author admin
     * @time 2019/8/22
     */
    fun getOrderDetail(orderId: String): Observable<BaseResp<ServiceOrderDetailRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getServiceOrder(orderId)
    }


    /**
     * @description 获取服务订单列表
     * @param
     * @return
     */
    fun getServiceOrderList(pageNum: Int, pageSize: Int): Observable<BaseResp<ServiceOrdersRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getServiceOrderList(pageNum, pageSize)

    }

    /**
     * @description 获取支付结果
     * @param
     * @return
     * @author admin
     * @time 2019/8/23
     */
    fun getPaymentResult(paymentId: String): Observable<BaseResp<PaymentResultRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getPaymentResult(paymentId)
    }

    /**
     * @description 保存支付结果信息
     * @param
     * @return
     * @author admin
     * @time 2019/8/23
     */
    fun savePaymentResult(savePaymentInfo: SavePaymentInfoReq): Observable<BaseResp<SavePaymentRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .savePaymentInfo(getRequestJsonBody(savePaymentInfo))
    }


    /**
     * @description 获取申请列表
     * @param
     * @return
     * @author admin
     * @time 2019/8/23
     */
    fun fetchApplyMedicineList(pageNum: Int, pageSize: Int): Observable<BaseResp<DataListRes<ApplyMedicineRes>>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .fetchMedicineApplyList(pageNum, pageSize)
    }

    /**
     * @description 申请药箱页面信息
     * @param
     * @return
     * @author admin
     * @time 2019/8/24
     */
    fun getApplyMedicineInfo(): Observable<BaseResp<ApplyReciveAddress>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .getApplyMedicineInfo()
    }


    /**
     * @description 获取申请列表
     * @param
     * @return
     * @author admin
     * @time 2019/8/23
     */
    fun getApprovalList(
        pageNum: Int,
        pageSize: Int,
        status: Int
    ): Observable<BaseResp<DataListRes<ApprovalItemRes>>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .fetchMedicineApprovalList(pageNum, pageSize, status)
    }


    /**
     * @description 审批/驳回 药箱审批
     * @param
     * @return
     * @author admin
     * @time 2019/8/23
     */
    fun approvalMedicineApply(
       obj: ApprovalResultReq
    ): Observable<EmptyResp> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .approvalMedicineApply(getRequestJsonBody(obj))
    }


    /**
     * @description 提交申请
     * @param
     * @return
     * @author admin
     * @time 2019/8/24
     */
    fun commitApply(commitApplyRes: CommitApplyDataReq): Observable<BaseResp<CommitApplyRes>> {
        return RetrofitFactory.instance
            .createApiService(WorkApi::class.java)
            .commitApply(getRequestJsonBody(commitApplyRes))
    }


}